class Solution {
public:
    bool backspaceCompare(string s, string t) {
        string st,tt;
        for(auto ch:s)
        {
            if(ch=='#')
            {
                if(st.size())st.pop_back();
            }
            else 
            {
                st+=ch;
            }
        }
        for(auto ch:t)
        {
            if(ch=='#')
            {
                if(tt.size())tt.pop_back();
            }
            else 
            {
                tt+=ch;
            }
        }
        if(tt==st)return true;
        else return false;
    }
};
